package de.dhbw.tinf11b.vfb;

import java.util.LinkedList;
import java.util.List;

import de.dhbw.tinf11b.vfb.exceptions.CurriculumNotFoundException;

public class CurriculumManager {
	
	
	private static CurriculumManager instance = null;
	/**
	 * Singleton-Pattern: get the curriculum manager instance.
	 * @return 
	 */
	public static CurriculumManager getInstance() {
		if (instance == null) {
			instance = new CurriculumManager();
		}
		
		return instance;
	}
	
	
	protected List<Curriculum> curricula = new LinkedList<Curriculum>();
	
	/**
	 * Add curriculum with its modules to curricula
	 * @param programName
	 * @param degreeType
	 * @param modules
	 */
	public void addCurriculum(String programName, DegreeType degreeType, List<Module> modules) {
		Curriculum curriculum = new Curriculum(programName, degreeType);
		
		for(Module module : modules) {
			curriculum.addModule(module);
		}
		
		this.curricula.add(curriculum);
	}
	
	
	/**
	 * Retrieve a curriculum by name.
	 * @param programName
	 * @return
	 * @throws CurriculumNotFoundException 
	 */
	public Curriculum getCurriculum(String programName) throws CurriculumNotFoundException {
		for (Curriculum c : curricula) {
			if (c.getProgramName().equals(programName)) return c;
		}
		throw new CurriculumNotFoundException();
	}
	
	
	
	
	
}
